package com.SmartCare.controller.manager;


import com.SmartCare.common.Result;
import com.SmartCare.pojo.medicine.Medication;
import com.SmartCare.service.medicine.MedicationService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

import javax.annotation.Resource;

/**
 * 药物表 前端控制器
 */
@RestController
@RequestMapping("/medication")
public class MedicationController {

    @Resource
    MedicationService medicationService;

    //添加药品信息
    @PostMapping("/add")
    public Result add(@RequestBody Medication medication) {
        return medicationService.addMedicine(medication);
    }

    //获取所有的药品信息
    @GetMapping("/getAll")
    public Result getAll(@RequestParam String careHomeName) {
        return medicationService.getAll(careHomeName);
    }

    //根据药品名的模糊查询
    @GetMapping("/search")
    public Result search(@RequestParam String keyword) {
        return medicationService.search(keyword);
    }

    //根据id修改药品信息
    @PutMapping("/edit")
    public Result edit(@RequestBody Medication medication) {
        return medicationService.edit(medication);
    }

    //根据id删除药品信息
    @DeleteMapping("/delete/{id}")
    public Result deleteMedication(@PathVariable Long id) {
        return medicationService.deleteById(id);
    }

    //导入
    @PostMapping("/import/{name}")
    public Result importMedication(@RequestParam MultipartFile file, @PathVariable String name) {
        return medicationService.importMedication(file, name);
    }

    //导出
    @GetMapping("/export/{name}")
    public void export(HttpServletResponse response, @PathVariable String name) {
        medicationService.export(response, name);
    }
}

